package com.ruoyi.project.rate.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.framework.web.service.CrudService;
import com.ruoyi.framework.web.service.DictService;
import com.ruoyi.project.rate.Constants;
import com.ruoyi.project.rate.domain.KhzDept;
import com.ruoyi.project.rate.mapper.KhzDeptMapper;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dict.domain.DictData;

@Service
public class KhzDeptService extends CrudService<KhzDeptMapper, KhzDept> {
	@Autowired
	private DictService dictService;
	
	/**
	 * 根据部门查询所属的考核组
	 * @param dept
	 * @return
	 */
	public List<DictData> getKhzDictDataDept(Dept dept) {
		List<DictData> dictDatas = this.dictService.getType(Constants.KHZ);
		Map<String, DictData> dictDataMap = new HashMap<String, DictData>();
		for (DictData dd : dictDatas) {
			dictDataMap.put(dd.getDictValue(), dd);
		}
		
		List<DictData> result = new ArrayList<DictData>();
		
		KhzDept k = new KhzDept();
		k.setDept(dept);
		List<KhzDept> list = this.findList(k);
		
		for (KhzDept khzDept : list) {
			String khz = khzDept.getKhz();
			DictData dd = dictDataMap.get(khz);
			if (dd != null) {
				result.add(dd);
			}
			dictDataMap.remove(khz);
		}
		return result;
	}
}
